<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2019/4/8
 * Time: 11:37
 */

namespace common\sources\read\pepperrecord;


use Yii;
use common\models\craftsman\BuyPepperRecord;

class PepperRecordAccess implements IPepperRecordAccess
{
    public function getCount($data)
    {
        return BuyPepperRecord::find()
                ->where(["buy_id" => $data['buy_id']])
                ->count();
    }

    public function getList($data)
    {
        return BuyPepperRecord::find()
                ->select("id,buy_id,task_order_num,expend,income,balance,remark,create_time")
                ->where(["buy_id" => $data['buy_id']])
                ->orderBy("id desc")
                ->offset(($data['page_num']-1)*$data['limit'])
                ->limit($data['limit'])
                ->asArray()
                ->all();
    }

    //获取任务奖励
    public function getTaskOrderAward($data)
    {
        $sql = "select sum(income) as income 
                from buy_pepper_record
                where buy_id=".$data['buy_id']." and type =7 and from_unixtime(create_time, '%Y-%m-%d') ='".$data['task_time']."'";
        return Yii::$app->db->createCommand($sql)->queryOne();

    }
}